package com.wutianyi.favority.bean;

import org.neo4j.graphdb.Node;

import com.wutianyi.favority.constants.Constants;

public class Link {
	private final Node underlyingNode;
	private int count;

	public Link(Node underlyingNode) {
		this.underlyingNode = underlyingNode;
	}

	public Node getUnderlyingNode() {
		return underlyingNode;
	}

	public String getLink() {
		return (String) underlyingNode.getProperty(Constants.LINK_INDEX);
	}

	public long getLinkId() {
		return underlyingNode.getId();
	}

	public void increCount() {
		underlyingNode.setProperty("count",
				((Integer) underlyingNode.getProperty("count", 0)) + 1);
	}

	public void desCount() {
		underlyingNode.setProperty("count",
				((Integer) underlyingNode.getProperty("count", 1)) - 1);
	}

	@Override
	public int hashCode() {
		return underlyingNode.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		return obj instanceof Link
				&& ((Link) obj).getUnderlyingNode().equals(underlyingNode);
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

}
